﻿using System;
using UnityEngine;

namespace Assets.Scripts.UI.Panel
{
    public class LoadingLoopPanel:UIBase<LoadingLoopPanel>
    {
        //如果服务器30秒内没有反应则，直接释放掉资源
        private float time_out = 30;//设置请求超时的时间

        private WWW www;
        private Action dispose;

        public void Init()
        {
            Invoke("DestroySelf", time_out);
        }

        public void Init(WWW www,Action dispose)
        {
            this.dispose = dispose;
            this.www = www;                      
            Invoke("DestroySelf",time_out);
        }

        private void DestroySelf()
        {
            UIManager._Instance.ShowTipInfo("链接超时，请尝试重新请求");
            Debug.Log("链接超时");
            Destroy(gameObject);
        }

        protected override void InitOnDisable()
        {            
            if (dispose != null)
            {
                dispose();
            }
            if (www != null)
            {
                www.Dispose();
            }            
        }

        protected override UIType UIType
        {
            get { return UIType.Panel;}
        }
    }
}